<?php 
$first_id = $last_id = null;
?>
<h2>Tweets</h2>

<h3>Tweets</h3>
<div id='tweets' class="wrap">
<?php 
for($i = 0, $cnt = count($tweets); $i < $cnt; $i++):
    $tweet = $tweets[$i];
    if ($i == 0) {
        $first_id = $tweet['id'];
    } 
    if ($i == ($cnt - 1)) {
        $last_id = $tweet['id'];
    }
?>
<?= $this->element('tweets/element', compact('tweet')) ?>
<?php 
endfor;
?>
</div><!-- /#tweets -->

<?php 
$default_url = array('action'=>'tweets');
if (!empty($twitter_id)) {
    $default_url['twitter_id'] = $twitter_id;
}
$newer_url = $older_url = $default_url;
if (!empty($first_id)) {
    $newer_url['since_id'] = $first_id;
}
if (!empty($last_id)) {
    $older_url['max_id'] = $last_id;
}
?>
<ul>
<li>
<?php echo $html->link('Prev', $newer_url); ?>
</li>
<li>
<?php echo $html->link('Older', $older_url); ?>
</li>
</ul>
